package com.earth.config;

import com.earth.utils.api.CommonResult;
import com.earth.utils.api.IErrorCode;
import com.earth.utils.api.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.rmi.ServerException;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(code=HttpStatus.INTERNAL_SERVER_ERROR)
    public CommonResult handleException(Exception e) {
        log.error("全局异常处理捕捉到业务异常：", e);
        return CommonResult.failed(e.getMessage());
    }

    @ExceptionHandler(ServerException.class)
    @ResponseStatus(code= HttpStatus.OK)
    public CommonResult serverException(ServerException e) {
        log.error("全局异常处理捕捉到业务异常：", e);
        return CommonResult.failed(e.getMessage());
    }
}
